package com.cloudfun.campusshare.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.constant.KjtAuditStatus;
import com.cloudfun.campusshare.common.constant.KjtWithdrawStatus;
import com.cloudfun.campusshare.common.exception.BusinessException;
import com.cloudfun.campusshare.common.model.dto.WithdrawHisDTO;
import com.cloudfun.campusshare.entity.WithdrawHisEntity;
import com.cloudfun.campusshare.repo.WithdrawHisRepo;
import com.cloudfun.campusshare.service.WithdrawHisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by CodeGenerator on 2020/08/17
 */
@Slf4j
@Service
public class WithdrawHisServiceImpl implements WithdrawHisService {

    @Autowired
    private WithdrawHisRepo withdrawHisRepo;

    @Override
    public void create(WithdrawHisDTO withdrawHisDTO) {
        WithdrawHisEntity withdrawHisEntity = withdrawHisRepo.findByOutTradeNo(withdrawHisDTO.getOutTradeNo());
        if (null != withdrawHisEntity && withdrawHisEntity.getWithdrawStatus() == KjtWithdrawStatus.WITHDRAWAL_SUCCESS) {
            throw new BusinessException(Code.DATA_EXIST, "提现历史已存在");
        }
        withdrawHisEntity = new WithdrawHisEntity();
        BeanUtil.copyProperties(withdrawHisDTO, withdrawHisEntity);
        withdrawHisRepo.save(withdrawHisEntity);
    }

}